package com.xuyuan.json.gson.custom;

import com.google.gson.*;
import com.xuyuan.json.gson.CustomBody;

import java.lang.reflect.Type;

public class CustomAdapter implements JsonDeserializer<CustomBody>, JsonSerializer<CustomBody> {
    @Override
    public CustomBody deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        return null;
    }

    /**
     * 将CustomBody写进集合
     *
     * @param o
     * @param type
     * @param jsonSerializationContext
     * @return
     */
    @Override
    public JsonElement serialize(CustomBody o, Type type, JsonSerializationContext jsonSerializationContext) {
        JsonArray jsonArray = new JsonArray();
        jsonArray.add(jsonSerializationContext.serialize(o));
        return jsonArray;
    }

}
